********************************
****** Main Paper Models *******
********************************

cd "Your_Directory\JCR_Jooetal_replication"
use FP_data.dta

xtset ltid year 

***********
* Table 1 *
*********** 
cd "Your_Directory\JCR_Jooetal_replication\Tables"

* Model 1
xtlogit pinit pinit_lag rightparti2 partipdem right2 cinc majpower atopally, vce (cluster ccode)
outreg2 using Tab1.doc, append dec(3) pdec(3) 


* Model 2
xtlogit pinit pinit_lag rightparti2 partipdem right2 cinc majpower atopally male leveledu, vce(cluster ccode)
outreg2 using Tab1.doc, append dec(3) pdec(3) 


* Model 3 
xtlogit pinit pinit_lag rightparti2 partipdem right2 cinc majpower atopally male leveledu militarycareer combat milcombat, vce(cluster ccode)
outreg2 using Tab1.doc, append dec(3) pdec(3) 


* Model 4
xtlogit pinit pinit_lag rightparti2 partipdem right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular , vce(cluster ccode)
outreg2 using Tab1.doc, append dec(3) pdec(3) 


* Model 5
xtlogit pinit pinit_lag rightparti2 partipdem right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime rival_dum , vce(cluster ccode)
outreg2 using Tab1.doc, append dec(3) pdec(3) 


***********
* Table 2 *
***********

* Model 6 - All right wing leader interaction model 
xtlogit pinit pinit_lag c.partipdem##i.leader_right cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime rival_dum , vce(cluster ccode)
outreg2 using Tab2.doc, append dec(3) pdec(3) 

* Model 7 - Left wing populist interaction 
xtlogit pinit pinit_lag c.partipdem##i.left2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime rival_dum , vce(cluster ccode)
outreg2 using Tab2.doc, append dec(3) pdec(3) 

* Model 8 - Left wing control 
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime rival_dum left2, vce(cluster ccode)
outreg2 using Tab2.doc, append dec(3) pdec(3) 

* Model 9 - Baseline Polity interaction
xtlogit pinit pinit_lag i.right2##c.polity2 cinc majpower atopally , vce(cluster ccode)
outreg2 using Tab2.doc, append dec(3) pdec(3) 

* Model 10 - Extra Polity interaction
xtlogit pinit pinit_lag i.right2##c.polity2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime rival_dum, vce(cluster ccode)
outreg2 using Tab2.doc, append dec(3) pdec(3) 



****************************************** 
****** Supplemental Appendix Models ******
******************************************

************
* Table A4 *
************

* Model A5
xtlogit pinit pinit_lag i.right2##c.polity2 cinc majpower atopally , vce(cluster ccode)
outreg2 using TabA4.doc, append dec(3) pdec(3)

* Model A6 
xtlogit pinit pinit_lag c.polity2##i.right2 cinc majpower atopally time1 time2 time3, vce (cluster ccode)
outreg2 using TabA4.doc, append dec(3) pdec(3)  

* Model A7
xtlogit pinit pinit_lag c.polity2##i.right2 cinc majpower atopally male leveledu time1 time2 time3 , vce (cluster ccode)
outreg2 using TabA4.doc, append dec(3) pdec(3) 

* Model A8
xtlogit pinit pinit_lag i.right2##c.polity2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime rival_dum , vce(cluster ccode)
outreg2 using TabA4.doc, append dec(3) pdec(3) 

* Model A9
xtlogit pinit pinit_lag i.right2##c.polity2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime rival_dum time1 time2 time3, vce(cluster ccode)
outreg2 using TabA4.doc, append dec(3) pdec(3) 

* Model A10
xtlogit pinit pinit_lag c.polity2##i.right2 cinc majpower atopally male leveledu irregular , vce (cluster ccode)
outreg2 using TabA4.doc, append dec(3) pdec(3) 

* Model A11
xtlogit pinit pinit_lag c.polity2##i.right2 cinc majpower atopally male leveledu irregular time1 time2 time3 , vce (cluster ccode)
outreg2 using TabA4.doc, append dec(3) pdec(3) 

* Model A12
xtlogit pinit pinit_lag c.polity2##i.right2 cinc majpower atopally male leveledu irregular age officetime rebel, vce (cluster ccode)
outreg2 using TabA4.doc, append dec(3) pdec(3) 

* Model A13
xtlogit pinit pinit_lag c.polity2##i.right2 cinc majpower atopally male leveledu irregular age officetime rebel time1 time2 time3, vce (cluster ccode)
outreg2 using TabA4.doc, append dec(3) pdec(3) 


***********
* Table 5 *
***********

* Model A14 - Autocracy 
xtlogit pinit pinit_lag i.autregime##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular , vce(cluster ccode)
outreg2 using TabA5.doc, append dec(3) pdec(3) 

* Model A15 - Anocracy 
xtlogit pinit pinit_lag i.anocracy##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular , vce(cluster ccode)
outreg2 using TabA5.doc, append dec(3) pdec(3) 

* Model A16 - Weeks Military 
xtlogit pinit pinit_lag i.weeks_military##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular , vce(cluster ccode)
outreg2 using TabA5.doc, append dec(3) pdec(3) 

* Model A17 - Weeks Personal 
xtlogit pinit pinit_lag i.weeks_personal##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular , vce(cluster ccode)
outreg2 using TabA5.doc, append dec(3) pdec(3) 

* Model A18 - GWF Military 
* Estimated via R 

* Model A19 - GWF Personal 
xtlogit pinit pinit_lag i.gwf_per##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular , vce(cluster ccode)
outreg2 using TabA5.doc, append dec(3) pdec(3)  

************
* Table A6 *
************

* Model A20
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime warwin warloss rebelwin rebelloss, vce (cluster ccode)
outreg2 using TabA6.doc, append dec(3) pdec(3) 

* Model A21 - Downturn
xtlogit pinit pinit_lag rightparti2 partipdem right2 neg_cc cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular , vce(cluster ccode)
outreg2 using TabA6.doc, append dec(3) pdec(3)

* Model A22 - Severe Decline
xtlogit pinit pinit_lag rightparti2 partipdem right2 cinc_crisis cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular , vce(cluster ccode)
outreg2 using TabA6.doc, append dec(3) pdec(3)

* Model A23 - Economic Slump
xtlogit pinit pinit_lag c.partipdem##i.right2 neg_ise cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular, vce(cluster ccode)
outreg2 using TabA6.doc, append dec(3) pdec(3)  

* Model A24 - Economic Distress
xtlogit pinit pinit_lag c.partipdem##i.right2 ise_crisis cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular, vce(cluster ccode)
outreg2 using TabA6.doc, append dec(3) pdec(3)

* Model A25 
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu irregular, vce(cluster ccode)
outreg2 using TabA6.doc, append dec(3) pdec(3)

* Model A26
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu rebel irregular age officetime, vce (cluster ccode)
outreg2 using TabA6.doc, append dec(3) pdec(3) 

clear 

************
* Table A7 *
************
cd "Your_Directory\JCR_Jooetal_replication"

use dyadicdata

xtset dirdyadid year 

cd "Your_Directory\JCR_Jooetal_replication\Tables"

* Model A27
xtlogit pinit1 pinit1_lag rightparti1 partipdem1 partipdem2 right1 right2 cinc1 cinc2 majpower1 majpower2 atopally, vce (cluster dirdyadid)
outreg2 using TabA7.doc, append dec(3) pdec(3)


* Model A28
xtlogit pinit1 pinit1_lag rightparti1 partipdem1 partipdem2 right1 right2 cinc1 cinc2 majpower1 majpower2 atopally male1 leveledu1, vce (cluster dirdyadid)
outreg2 using TabA7.doc, append dec(3) pdec(3)


* Model A29
xtlogit pinit1 pinit1_lag rightparti1 partipdem1 partipdem2 right1 right2 cinc1 cinc2 majpower1 majpower2 atopally male1 leveledu1 milcombat1 militarycareer1 combat1, vce (cluster dirdyadid)
outreg2 using TabA7.doc, append dec(3) pdec(3)


* Model A30
xtlogit pinit1 pinit1_lag rightparti1 partipdem1 partipdem2 right1 right2 cinc1 cinc2 majpower1 majpower2 atopally male1 leveledu1 milcombat1 militarycareer1 combat1 rebel1 irregular1, vce (cluster dirdyadid)
outreg2 using TabA7.doc, append dec(3) pdec(3)


* Model A31
xtlogit pinit1 pinit1_lag partipdem1 partipdem2 i.right1##i.rival_dum right2 cinc1 cinc2 majpower1 majpower2 atopally male1 leveledu1 milcombat1 militarycareer1 combat1 rebel1 irregular1, vce (cluster dirdyadid)
outreg2 using TabA7.doc, append dec(3) pdec(3)


************
* TABLE A8 *
************
cd "Your_Directory\JCR_Jooetal_replication"

use FP_data.dta

xtset ltid year 

cd "Your_Directory\JCR_Jooetal_replication\Tables"

* Model A32
relogit right2 rival_dum majpower atopally neg_cc ltrade anocracy, cluster(ccode)
outreg2 using TabA8.doc, append dec(3) pdec(3)

* Model A33
relogit right2 pinit_lag majpower atopally neg_cc ltrade anocracy, cluster(ccode)
outreg2 using TabA8.doc, append dec(3) pdec(3)

* Model A34
xtlogit pinit pinit_lag i.right2##i.rival_dum cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime, vce(cluster ccode)
outreg2 using TabA8.doc, append dec(3) pdec(3)

* Models A35-A36
biprobit (pinit = rival_dum pinit_lag rightparti2 partipdem right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime) (right2 = rival_dum pinit_lag majpower atopally neg_cc anocracy ltrade ), vce(r)
outreg2 using TabA8.doc, append dec(3) pdec(3)

clear

************
* Table A9 *
************
cd "Your_Directory\JCR_Jooetal_replication"

use FP_data.dta

xtset ltid year 

cd "Your_Directory\JCR_Jooetal_replication\Tables"

* Model A37
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally time1 time2 time3, vce (cluster ccode)
outreg2 using TabA9.doc, append dec(3) pdec(3) 

* Model A38
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu time1 time2 time3, vce(cluster ccode)
outreg2 using TabA9.doc, append dec(3) pdec(3) 

* Model A39
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat time1 time2 time3, vce(cluster ccode)
outreg2 using TabA9.doc, append dec(3) pdec(3) 

* Model A40
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular time1 time2 time3, vce(cluster ccode)
outreg2 using TabA9.doc, append dec(3) pdec(3) 

* Model A41
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu irregular time1 time2 time3 , vce (cluster ccode)
outreg2 using TabA9.doc, append dec(3) pdec(3) 

* Model A42
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu irregular age officetime rebel time1 time2 time3, vce (cluster ccode)
outreg2 using TabA9.doc, append dec(3) pdec(3) 

* Model A43
xtlogit pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular age officetime rival_dum time1 time2 time3, vce(cluster ccode)
outreg2 using TabA9.doc, append dec(3) pdec(3) 

clear


************
* TABLE 10 *
************
cd "Your_Directory\JCR_Jooetal_replication"

use FP_data.dta

xtset ltid year 

cd "Your_Directory\JCR_Jooetal_replication\Tables"

* Model A44
relogit pinit pinit_lag rightparti2 right2 partipdem cinc majpower atopally, cluster(ccode)
outreg2 using TabA10.doc, append dec(3) pdec(3) 


* Model A45
relogit pinit pinit_lag rightparti2 right2 partipdem cinc majpower atopally male leveledu, cluster(ccode)
outreg2 using TabA10.doc, append dec(3) pdec(3) 


* Model A46
relogit pinit pinit_lag rightparti2 right2 partipdem cinc majpower atopally male leveledu militarycareer combat milcombat, cluster(ccode)
outreg2 using TabA10.doc, append dec(3) pdec(3) 


* Model A47
relogit pinit pinit_lag rightparti2 right2 partipdem cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular, cluster(ccode)
outreg2 using TabA10.doc, append dec(3) pdec(3) 

* Model A48
xtprobit pinit pinit_lag rightparti2 right2 partipdem cinc majpower atopally, vce (cluster ccode)
outreg2 using TabA10.doc, append dec(3) pdec(3) 


* Model A49
xtprobit pinit pinit_lag rightparti2 right2 partipdem cinc majpower atopally male leveledu, vce (cluster ccode)
outreg2 using TabA10.doc, append dec(3) pdec(3) 


* Model A50
xtprobit pinit pinit_lag rightparti2 right2 partipdem cinc majpower atopally male leveledu militarycareer combat milcombat,vce (cluster ccode)
outreg2 using TabA10.doc, append dec(3) pdec(3) 


* Model A51
xtprobit pinit pinit_lag rightparti2 right2 partipdem cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular, vce (cluster ccode)
outreg2 using TabA10.doc, append dec(3) pdec(3) 

clear


************
* TABLE 11 *
************

cd "Your_Directory\JCR_Jooetal_replication"

use residualdata

cd "Your_Directory\JCR_Jooetal_replication\Tables"

log using TabA11_logistic

corrgram resid0
corrgram resid1
corrgram resid2
corrgram resid3
corrgram resid4

log close

cd "Your_Directory\JCR_Jooetal_replication"

use residual_GEE

cd "Your_Directory\JCR_Jooetal_replication\Tables"

log using TabA11_GEE

corrgram resid0
corrgram resid1
corrgram resid2
corrgram resid3
corrgram resid4

log close 

clear


************
* TABLE 12 *
************
cd "Your_Directory\JCR_Jooetal_replication"

use FP_data.dta

xtset ltid year 

cd "Your_Directory\JCR_Jooetal_replication\Tables"

* Model A52 
xtgee pinit c.partipdem##i.right2 cinc majpower atopally time1 time2 time3,  vce(r) family(b) link(logit)
outreg2 using TabA12.doc, append dec(3) pdec(3) 

* Model A53
xtgee pinit c.partipdem##i.right2 cinc majpower atopally male leveledu time1 time2 time3,  vce(r) family(b) link(logit)
outreg2 using TabA12.doc, append dec(3) pdec(3) 

* Model A54
xtgee pinit c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat time1 time2 time3,  vce(r) family(b) link(logit)
outreg2 using TabA12.doc, append dec(3) pdec(3) 

* Model A55
xtgee pinit c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular time1 time2 time3,  vce(r) family(b) link(logit)
outreg2 using TabA12.doc, append dec(3) pdec(3) 

* Model A56
xtgee pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally time1 time2 time3,  vce(r) family(b) link(logit)
outreg2 using TabA12.doc, append dec(3) pdec(3) 

* Model A57
xtgee pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu time1 time2 time3,  vce(r) family(b) link(logit)
outreg2 using TabA12.doc, append dec(3) pdec(3) 

* Model A58
xtgee pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat time1 time2 time3,  vce(r) family(b) link(logit)
outreg2 using TabA12.doc, append dec(3) pdec(3) 

* Model A59
xtgee pinit pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular time1 time2 time3,  vce(r) family(b) link(logit)
outreg2 using TabA12.doc, append dec(3) pdec(3) 

clear


*************
* TABLE A13 *
*************
cd "Your_Directory\JCR_Jooetal_replication"

use FP_data.dta

xtset ltid year 

cd "Your_Directory\JCR_Jooetal_replication\Tables"

cem refugees migrant_pct unemployment cinc, treatment(right2)

* Model A60
logit pinit pinit_lag rightparti2 partipdem right2 cinc majpower atopally [iw=cem_weights], vce(cl ccode) 
outreg2 using TabA13.doc, append dec(3) pdec(3) 

* Model A61
logit pinit pinit_lag rightparti2 partipdem right2 cinc majpower atopally male leveledu  [iw=cem_weights], vce(cl ccode) 
outreg2 using TabA13.doc, append dec(3) pdec(3) 

* Model A62
logit pinit pinit_lag rightparti2 partipdem right2 cinc majpower atopally male leveledu militarycareer combat milcombat  [iw=cem_weights], vce(cl ccode) 
outreg2 using TabA13.doc, append dec(3) pdec(3) 

* Model A63
logit pinit pinit_lag rightparti2 partipdem right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular [iw=cem_weights], vce(cl ccode) 
outreg2 using TabA13.doc, append dec(3) pdec(3) 

*ssc install rbiprobit

* Model A64
rbiprobit pinit = pinit_lag c.partipdem##i.right2 cinc majpower atopally, endogenous(right2 = cinc majpower combat irregular warloss)
outreg2 using TabA13.doc, append ctitle(Model A28)

* Model A65
rbiprobit pinit = pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu, endogenous(right2 = cinc majpower combat irregular warloss)
outreg2 using TabA13.doc, append ctitle(Model A29)

* Model A66
rbiprobit pinit = pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat, endogenous(right2 = cinc majpower combat irregular warloss)
outreg2 using TabA13.doc, append ctitle(Model A30)

* Model A67
rbiprobit pinit = pinit_lag c.partipdem##i.right2 cinc majpower atopally male leveledu militarycareer combat milcombat rebel irregular, endogenous(right2 = cinc majpower combat irregular warloss)
outreg2 using TabA13.doc, append ctitle(Model A31)

clear 

** End of Do-File